<?php
namespace app\servergoods\service\goods;

use \app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-05-31 16:29:22
 * @Description: 商品模块
 */
class Goods extends ApiBase
{
    protected $goodsLogic = '\app\servergoods\logic\Goods';
    protected $goodsValidate = '\app\servergoods\validate\Goods';

    use \app\serveruser\traits\AddAppIdToRunOne;

    //获取某一商品全部详情
    public function goodsAllDetail(): array 
    {
    	$data = $this->receiveData(['id'=>0, 'token'=>' ']);
        return $this->stepRun($data, 'servergoods/goods/Goods/managerGoodsDetail', 'goodsAllDetail', 'goodsAllDetail');
    }
    //管理员删除商品
    public function manageDelGoods(): array 
    {
        $data = $this->receiveData(['id'=>0,'token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/manageDelGoods', $this->goodsValidate, $this->goodsLogic, false);
    }
    /*管理员批量删除商品*/
    public function manageBatchDelGoods(): array 
    {
        $data = $this->receiveData(['id'=>[],'token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/manageBatchDelGoods', $this->goodsValidate, $this->goodsLogic, false,'manageBatchDelGoods');
    }
     /*管理员审核某一个商品*/
    public function auditOneGoods(): array 
    {

        $data = $this->receiveData(['id'=>0,'status'=>0,'token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/auditOneGoods', $this->goodsValidate, $this->goodsLogic, false,'auditOneGoods');

    }
    /*管理员审核某一批商品*/
    public function batchAuditGoods(): array 
    {

        $data = $this->receiveData(['id'=>[],'status'=>0,'token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/batchAuditGoods', $this->goodsValidate, $this->goodsLogic, false,'batchAuditGoods');

    }
    /*管理员推荐某个商品*/
    public function recommend(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'recommend'=>'','token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/recommend', $this->goodsValidate, $this->goodsLogic, false, 'recommend');
    }
    
    /*管理员下架某一个商品*/
    public function soldOutOneGoods(): array 
    {
        $data = $this->receiveData(['id'=>0,'token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/soldOutOneGoods', $this->goodsValidate, $this->goodsLogic, false,'soldOutOneGoods');
    }

    /*管理员下架某一批商品*/
    public function soldOutBatchGoods(): array 
    {
        $data = $this->receiveData(['id'=>[],'token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/soldOutBatchGoods', $this->goodsValidate, $this->goodsLogic, false,'soldOutBatchGoods');
    }

    /*管理员获取商品列表*/
    public function adminGoodsList(): array 
    {
        $data = $this->issetReceiveData(['status'=>0,'page'=>1,'listRows'=>15,'cate_id'=>0,'keywords'=>'','price_start'=>0,'price_end'=>0,'symbol'=>'','search_fields'=>[],'is_sell'=>'','token'=>' ']);
        return $this->stepRun($data, 'servergoods/goods/Goods/adminGoodsList', 'adminGoodsList', 'adminGoodsList');
    }

    //艺货管理员发布商品 v2:新增3个字段
    public function yihuoAddGoods(): array 
    {
        $data = $this->haveIssetReceiveData(['goods_belonger_name'=>' ','cate_id'=>0,'title'=>' ','authors'=>'','imgs_ids'=>' ','imgs_urls'=>' ','price'=>0,'desc'=>'','goods_attrs'=>[],'organization'=>'','orther_info'=>[],'orther_price'=>[],'profile_pic'=>'','origin_number'=>0,'pick_up_time'=>0,'start_delivery_time'=>0,'end_delivery_time'=>0,'token'=>' ','latest_refund_time'=>0,'img_desc'=>'','text_desc'=>'']);
        return $this->stepRun($data, 'serveruser/auth/Token/hGetAll,serveruser/user/User/info,servercoding/coding/Coding/getCoding,serveruser/auth/App/find,servergoods/goods/Goods/yihuoAddGoods', 'yihuoAddGoods', 'yihuoAddGoods', 1, $this->goodsValidate, $this->goodsLogic);
    }

    /*艺货管理员编辑某个商品*/
    public function yihuoEditGoods(): array 
    {
        $data = $this->issetReceiveData(['id'=>0,'goods_belonger_name'=>' ','cate_id'=>0,'title'=>' ','authors'=>'','imgs_urls'=>' ','imgs_ids'=>' ','price'=>0,'desc'=>' ','goods_attrs'=>[],'organization'=>'','orther_info'=>[],'orther_price'=>'','profile_pic'=>'','number'=>0, 'origin_number'=>0,'pay_method'=>0,
        'delivery_type'=>1,'delivery_area'=>'','province'=>0,'city'=>0,'county'=>0,'order'=>100,'start_time'=>0,'end_time'=>0,'seo_key'=>'','pick_up_time'=>0,'start_delivery_time'=>0,'end_delivery_time'=>0,'token'=>' ','latest_refund_time'=>0,'img_desc'=>'','text_desc'=>'']);
        return $this->stepRun($data, 'serveruser/auth/Token/hGetAll,serveruser/auth/App/find,servergoods/goods/Goods/yihuoEditGoods', 'yihuoEditGoods', 'yihuoEditGoods', 1, $this->goodsValidate, $this->goodsLogic);

    }    

    /*艺货 - 添加一条与艺术家的账单*/
    public function addAccountBook(): array 
    {
        $data = $this->haveIssetReceiveData(['goods_id'=>0, 'order_number'=>0, 'total_price'=>0, 'remark'=>' ', 'token'=>' ']);
        return $this->stepRun($data, 'serveruser/auth/Token/hGetAll,servergoods/goods/Goods/addAccountBook', '', 'addAccountBook', '1', $this->goodsValidate, $this->goodsLogic);
    }

    /*艺货 - 标注该账单已结算*/
    public function signSettlement(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'token'=>' ']);
        return $this->stepRun($data, 'serveruser/auth/Token/hGetAll,servergoods/goods/Goods/signSettlement', '', 'signSettlement', '1', $this->goodsValidate, $this->goodsLogic);
    }

    /*艺货 - 获取账单分页列表*/
    public function allAccountBookList(): array 
    {
        $data = $this->haveIssetReceiveData(['page'=>1,'listRows'=>15, 'keywords'=>'']);
        return $this->oneStepRun($data, 'servergoods/goods/Goods/allAccountBookList', '', '1', $this->goodsValidate, $this->goodsLogic);
    }

    /*后台给某一个商品改价(人民币/艺货币)或增加库存*/
    public function changePriceNumber(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'price'=>'', 'currency'=>'', 'add_number'=>'', 'token'=>' ']);
        if(!$data['price'] && !$data['currency'] && !$data['add_number']){
            return verify_err(null, '价格与库存增量必须填一个');
        }
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/Goods/changePriceNumber', $this->goodsValidate, $this->goodsLogic);
    }

    /*后台管理员批量修改艺货商品的价格*/
    public function batchChangePrice(): array 
    {
        $data = $this->haveIssetReceiveData(['cate_id'=>'', 'multiple'=>1, 'currency_multiple'=>1]);
        return $this->oneStepRun($data, 'servergoods/goods/Goods/batchChangePrice', '', '1', $this->goodsValidate, $this->goodsLogic);
    }
    /*今周新增商品/商品总量*/
    public function goodsIncreTendency(): array 
    {
        $data = $this->haveIssetReceiveData(['dbDateFormat'=>'%y-%m-%d', 'dateFormat'=>'y-m-d', 'token'=>' ']);
        return $this->oneStepRun($data, 'servergoods/goods/Goods/goodsIncreTendency', '');
    } 


}